/*
Copyright (c) 2009, Evandro Rosa Santos <evandro.santos@email.com>
All rights reserved.

Redistribution and use in source and binary forms, with or
without modification, are permitted provided that the following
conditions are met:

  * Redistributions of source code must retain the above
    copyright notice, this list of conditions and the following
    disclaimer.
  * Redistributions in binary form must reproduce the above
    copyright notice, this list of conditions and the following
    disclaimer in the documentation and/or other materials
    provided with the distribution.
  * Neither the name of the Evandro Rosa Santos <evandro.santos@email.com>
    nor the names of its contributors may be used to endorse or promote products
    derived from this software without specific prior written
    permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
 */

package com.w5hh.login.main;

import com.w5hh.login.dao.AbstractDao;
import com.w5hh.login.dao.CrudDao;
import com.w5hh.login.factory.DaoFactory;
import com.w5hh.login.vo.Application;
import com.w5hh.login.vo.Permission;
import com.w5hh.login.vo.Place;
import com.w5hh.login.vo.Profile;
import com.w5hh.login.vo.User;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 *
 * @author Evandro Rosa Santos <evandro.santos@email.com>
 */
public class Main {

    public static void main(String args[]) {
        Application application = null;
        Permission permission = null;
        Place place = null;
        Profile profile = null;
        User user = null;
        User tester = null;

        DaoFactory factory = new DaoFactory("LoginPU");

        AbstractDao dao = factory.<CrudDao>getDao(CrudDao.class);
        
        // Applications
        application = new Application();
        application.setApplication("Logbook");
        dao.create(application);

        application = new Application();
        application.setApplication("Monitor");     
        dao.create(application);

        // Permissions
        Set<Permission> perminions = new HashSet<Permission>();
        permission = new Permission();
        permission.setPermission("manager");
        dao.create(permission);
        perminions.add(permission);

        permission = new Permission();
        permission.setPermission("client");
        dao.create(permission);
        perminions.add(permission);
        
        // Place
        Set<Place> places = new HashSet<Place>();
        place = new Place();
        place.setPlace("USA");
        dao.create(place);
        places.add(place);

        place = new Place();
        place.setPlace("BRA");
        dao.create(place);
        places.add(place);

        // Profile
        List<Profile> profiles = new ArrayList<Profile>();
        profile = new Profile();
        profile.setApplication(application);
        profile.setProfile("admin");
        profile.setPermissions(perminions);
        profile.setPlaces(places);
        dao.create(profile);
        profiles.add(profile);


        // User
        user = new User();
        user.setManager(user);
        user.setName("Developer");
        user.setProfiles(profiles);
        user.setRegister(new Date());
        user.setTimeOfLogin(new Date());
        user.setUserName("Evandro");
        dao.create(user);

        tester = new User();
        tester.setManager(user);
        tester.setName("Tester");
        tester.setProfiles(profiles);
        tester.setRegister(new Date());
        tester.setTimeOfLogin(new Date());
        tester.setUserName("Evandro");
        dao.create(tester);


        factory.close();
    }
}
